package com.hsh.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.hsh.persist.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * <p>
 * 字典数据表
 * </p>
 *
 * @author 黄思海
 * @since 2021-08-25
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_dict_data")
public class SysDictData extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 字典类型 ID PK
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 字典类型所属模块 fk
     */
    private String dictType;

    /**
     * 父级编号
     */
    private Long parentId;

    /**
     * 祖级列表【逗号相隔】
     */
    private String ancestors;

    /**
     * 字典排序
     */
    private Integer dictSort;

    /**
     * 字典标签
     */
    private String dictKey;

    /**
     * 字典键值
     */
    private String dictValue;

    /**
     * 是否默认（Y是 N否）
     */
    private String isDefault;

    /**
     * 状态（0正常 1停用）
     */
    private String status;


    /**
     * 备注
     */
    private String remark;

    @TableField(exist = false)
    private List<SysDictData> children = Collections.emptyList();

    public static Comparator<SysDictData> order() {
        return (o1, o2) -> {
            if (!o1.getDictSort().equals(o2.getDictSort())) {
                return (int) (o1.getDictSort() - o2.getDictSort());
            }
            return 0;
        };
    }
}
